'''
Created on June 15, 2011

@author: yc30rr1
'''
from library.AutoLoad import AutoLoad
from logging import getLogger
import os
import string
log = getLogger(__name__)

class FileHelper(object):
    '''
    classdocs
    '''
    
    def getfileNameList(self,fileLocation,*args):
        """
        Method search the filename in the specified location and it 
        return the list filenames if found at specified location or else return empty
        """
        log.debug("Getting list file name from specified location")
        try:
            
            fileList = []
            for file in os.listdir(fileLocation):
                dirfile = os.path.join(fileLocation, file)
                if os.path.isfile(dirfile):
                    if len(args) == 0:
                        fileList.append(dirfile)
                    else:
                        if os.path.splitext(dirfile)[1][1:] in args:
                            fileList.append(dirfile)
               
            return fileList
        except:
            log.critical("Unable to find the files in specified location")
    
    def getfileName(self,filenameList):
        """
        This method used to remove the filename extension and it return the filename alone
        """
        nameList=[]
        for i in range(len(filenameList)):
            filename=filenameList[i]
            nameList.append(filename[string.rfind(filename,'\\')+1:len(filename)])
            
        return nameList
            
 
